package com.ror.jvm.direct.memory;

import sun.misc.Unsafe;
import java.io.IOException;

public class Demo02Unsafe {
    static long _1Gb = 1024 * 1024 * 1024;

    public static void main(String[] args) throws IOException {
        Unsafe unsafe = Unsafe.getUnsafe();
        // 分配直接内存
        long base = unsafe.allocateMemory(_1Gb);
        unsafe.setMemory(base, _1Gb, (byte) 0);
        System.in.read();

        // 释放直接内存
        unsafe.freeMemory(base);
        System.in.read();
    }
}
